Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UX improvements: FFI logging, error message fix, Rust stream borrow checks #515

Merged
merged 15 commits into from
Nov 3, 2023

Conversation

dmitrii-ubskii
Copy link
Member

@dmitrii-ubskii dmitrii-ubskii commented Nov 3, 2023

What is the goal of this PR?

We improve the UX of Driver usage in several ways:

  • [Rust/Java/Python] Fix the formatting of error messages received from the server during a transaction.
  • [Java] Fix native error message formatting.
  • [Java/Python] Add the ability to enable Rust logging over FFI (resolves Enable Rust logging over FFI #482).
    • The granularity of the logs is controlled by the TYPEDB_DRIVER_LOG_LEVEL environment variable, which can be set to any value of error (default), warn, info, debug, or trace, in order of increasing verbosity. Setting the value to "typedb_driver=info" will show only the typedb-driver messages.
    • More advanced syntax is described in the env_logger documentation
  • [Rust] Network streams now borrow the transaction, so that the transaction can't be mistakenly dropped. (resolves Rust: Streams should borrow the transaction #449)

@typedb-bot
Copy link
Member

typedb-bot commented Nov 3, 2023

PR Review Checklist

Do not edit the content of this comment. The PR reviewer should simply update this comment by ticking each review item below, as they get completed.


Trivial Change

  • This change is trivial and does not require a code or architecture review.

Code

  • Packages, classes, and methods have a single domain of responsibility.
  • Packages, classes, and methods are grouped into cohesive and consistent domain model.
  • The code is canonical and the minimum required to achieve the goal.
  • Modules, libraries, and APIs are easy to use, robust (foolproof and not errorprone), and tested.
  • Logic and naming has clear narrative that communicates the accurate intent and responsibility of each module (e.g. method, class, etc.).
  • The code is algorithmically efficient and scalable for the whole application.

Architecture

  • Any required refactoring is completed, and the architecture does not introduce technical debt incidentally.
  • Any required build and release automations are updated and/or implemented.
  • Any new components follows a consistent style with respect to the pre-existing codebase.
  • The architecture intuitively reflects the application domain, and is easy to understand.
  • The architecture has a well-defined hierarchy of encapsulated components.
  • The architecture is extensible and scalable.

@@ -180,6 +180,7 @@ test_for_each_arg! {
let age = unwrap_long(age?.map.remove("age").unwrap());
assert_eq!(age, 1);
}
drop(ages);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ages (a Stream) now borrows the transaction

Comment on lines +108 to +109
let answer = context.transaction().query().get(&parsed.to_string())?.try_collect::<Vec<_>>().await?;
context.answer = answer;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to write this on one line, but the borrow checker gets confused by the .await, and thinks that we attempt to borrow context twice at the same time.

Comment on lines +262 to +264
break collector
.close(ConnectionError::TransactionIsClosedWithErrors(err.message().to_owned()))
.await
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the correct error message rather than Status::to_string()

Comment on lines -31 to -33
@Nullable
private final com.vaticle.typedb.driver.jni.Error nativeError;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer store the native error and instead just take its message.

Comment on lines +34 to +40
#[no_mangle]
pub extern "C" fn init_logging() {
const ENV_VAR: &str = "TYPEDB_DRIVER_LOG_LEVEL";
if let Err(err) = env_logger::try_init_from_env(Env::new().filter(ENV_VAR)) {
warn!("{err}");
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function allows the FFI drivers to initialize the Rust logger. (Rust driver users can do this directly)

@dmitrii-ubskii dmitrii-ubskii marked this pull request as ready for review November 3, 2023 14:14
@dmitrii-ubskii dmitrii-ubskii changed the title UX improvements UX improvements: FFI logging, error message fix, Rust stream borrow checks Nov 3, 2023
@flyingsilverfin flyingsilverfin added this to the 2.25.0 milestone Nov 3, 2023
@dmitrii-ubskii dmitrii-ubskii merged commit 96be0f6 into typedb:development Nov 3, 2023
@dmitrii-ubskii dmitrii-ubskii deleted the error-ux branch November 6, 2023 13:12
dmitrii-ubskii added a commit to dmitrii-ubskii/typedb-driver that referenced this pull request Jan 8, 2024
…hecks (typedb#515)

## What is the goal of this PR?

We improve the UX of Driver usage in several ways:

- [Rust/Java/Python] Fix the formatting of error messages received from
the server during a transaction.
- [Java] Fix native error message formatting.
- [Java/Python] Add the ability to enable Rust logging over FFI
(resolves typedb#482).
- The granularity of the logs is controlled by the
`TYPEDB_DRIVER_LOG_LEVEL` environment variable, which can be set to any
value of `error` (default), `warn`, `info`, `debug`, or `trace`, in
order of increasing verbosity. Setting the value to
`"typedb_driver=info"` will show only the typedb-driver messages.
- More advanced syntax is described in [the env_logger
documentation](https://docs.rs/env_logger/latest/env_logger/index.html#enabling-logging)
- [Rust] Network streams now borrow the transaction, so that the
transaction can't be mistakenly dropped. (resolves typedb#449)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable Rust logging over FFI Rust: Streams should borrow the transaction
3 participants